package com.qmyx.supply.admin.controller;

import com.ytjj.qmyx.supplychain.common.api.CommonResult;
import com.ytjj.qmyx.supplychain.common.model.request.ReissueLogisticsRequest;
import com.ytjj.qmyx.supplychain.common.model.request.ReissueLogisticsUpdateRequest;
import com.ytjj.qmyx.supplychain.service.BankerService;
import com.ytjj.qmyx.supplychain.service.ReissueLogisticsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 补单管理（供应商系统）
 * @Version: 1.0
 */
@RestController
@RequestMapping("/reissueLogistics")
public class ReissueLogisticsController {

    @Resource
    private ReissueLogisticsService reissueLogisticsService;
    @Autowired
    private BankerService bankerService;

    @PostMapping("/list")
    public CommonResult selectList(@RequestBody ReissueLogisticsRequest reissueLogisticsRequest){
        reissueLogisticsRequest.setBankerId(bankerService.getUserInfo().getId());
        return CommonResult.success(reissueLogisticsService.selectList(reissueLogisticsRequest));
    }

    @PostMapping("/updateLogistics")
    public CommonResult updateLogistics(@RequestBody ReissueLogisticsRequest reissueLogisticsRequest){
        int count = reissueLogisticsService.updateLogistics(reissueLogisticsRequest);
        if (count > 0) {
            return CommonResult.success(count);
        } else {
            return CommonResult.failed();
        }
    }

    @PostMapping("/refuseStatus")
    public CommonResult refuseStatus(@RequestBody ReissueLogisticsUpdateRequest request){
        int count = reissueLogisticsService.refuseStatusAndReason(request.getId(),request.getRefuseReason());
        if (count > 0) {
            return CommonResult.success(count);
        } else {
            return CommonResult.failed();
        }
    }

}
